package com.zxj.schoolxianyu.service;


import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.zxj.schoolxianyu.dao.conversationDao;
import com.zxj.schoolxianyu.entity.conversation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class getChatListService {

    @Autowired(required = false)
    private conversationDao conversationDao;

    public String ChatList(String username) {
        EntityWrapper<conversation> c1 = new EntityWrapper<>();
        EntityWrapper<conversation> c2 = new EntityWrapper<>();
        c1.eq("user1",username);
        c2.eq("user2",username);
        List<conversation> cs1 = conversationDao.selectList(c1);
        List<conversation> cs2 = conversationDao.selectList(c2);
        List<conversation> cs = new ArrayList<conversation>();
        cs.addAll(cs1);
        cs.addAll(cs2);
        if(cs.isEmpty()) return "No more data";
        else return JSON.toJSONString(cs);
    }
}
